package ink.liaoxuefeng.reflectprocess;

/**
 * @author wangzhuangzhuang
 * @DESC:
 * @date 2022-01-25 16:54
 */
public class MainPlusDemo01 {
	public static void main(String[] args) throws Exception{
		Class stdClass = Student.class;
		// 获取public字段 "score"
		System.out.println(stdClass.getField("score"));
		// 获取继承的public字段 "name"
		System.out.println(stdClass.getField("name"));
		// 获取private字段 "grade"
		System.out.println(stdClass.getDeclaredField("grade"));
		System.out.println("============================================");
		// 获取public方法getScore, 参数为String
		System.out.println(stdClass.getMethod("getScore", String.class));
		// 获取继承的public方法getName，无参数
		System.out.println(stdClass.getMethod("getName"));
		// 获取private方法getGrade，参数为int
		System.out.println(stdClass.getDeclaredMethod("getGrade", int.class));
	}
//	public int ink.liaoxuefeng.reflectprocess.Student.score
//	public java.lang.String ink.liaoxuefeng.reflectprocess.Person.name
//	public int ink.liaoxuefeng.reflectprocess.Student.grade

}

class Student extends Person{
	public int score;
	public int grade;

	public int getScore(String type){
		return 99;
	}

	public int getGrade(int year){
		return 1;
	}
}

class Person{
	public String name;
}

/**
 * 一个Method对象包含一个方法的所有信息：
 * * getName(): 返回方法名称 eg: getScore
 * * getReturnType(): 返回方法返回值类型
 * */